<template>
	<view class="confirmOrder">
		<n-loading></n-loading>
		<view v-if="orderInfo">
			<!-- 配送方式选择 -->
			<view class="deliveryMethod mb16" 
				>
				<view class="navBox">
					<view class="nav" :class="{navEd:methodItem==1}" @tap="deliveryMethod(1)">
						<image class="deMethodEd" src="../../static/svgIcon/dMethodEd1.svg" v-if="methodItem==1"></image>
						自助取货
					</view>
					<view class="nav" :class="{navEd:methodItem==0}" @tap="deliveryMethod(0)">
						<image class="deMethodEd" src="../../static/svgIcon/dMethodEd2.svg" v-if="methodItem==0"></image>
						线上发货
					</view>
				</view>
				<view class="tips" v-if="methodItem==1">选择自助取货，可在<text style="font-weight: bold;">“我的-我的酒卡”</text>里查看，您可凭借酒卡随时到门店进行提酒。</view>
				<view class="tips" v-if="methodItem==0">选择线上发货，将为您进行线上物流发货，这需要获取您的收货地址。</view>
			</view>
			<!-- 地址 -->
			<view class="tipsContBox mb16" 
			v-if="methodItem==0">
				<view class="tipsCont" v-if="detailParams.address != null" @tap="addAddress">
					<view class="tipsContTit">
						<text>{{detailParams.address.name}}</text>
						<text>{{detailParams.address.phone}}</text>
					</view>
					<view class="tipsContInfo">{{detailParams.address.address}}</view>
				</view>
				<view class="tipsCont" @tap="addAddress" v-if="detailParams.address.address == null">
					<view class="tipsContTit">无收货地址</view>
				</view>
				<u-icon name="arrow-right" color="#999999" size="20"></u-icon>
			</view>
			<!-- 购物清单 -->
			<view class="shoppingList mb16">
				<!-- <view class="title">购物清单</view> -->
				<view class="shopInfo">
					<dh-image class="shopLogo" :src="orderInfo.logo==null?'../../static/img/vector.svg':orderInfo.logo"
					 errorSrc="https://lovebirdopen.com/static/img/cBj/dPicture.png"></dh-image>
					 <view class="shopName ellipsis">{{orderInfo.checkedShop.name}}</view>
				</view>
				<view class="goodsInfo" >
					<!-- <image :src="orderInfo.goods.image" mode=""></image> -->
					<dh-image class="niccImg" :src="orderInfo.image" errorSrc="https://lovebirdopen.com/static/img/cBj/dPicture.png"></dh-image>
					<view class="goodsInfoFr">
						<view class="goodsName ellipsis">{{orderInfo.checkedShop.name}}</view>
						<view class="goodsLabel">
							<view>{{orderInfo.checkedShop.spec}}</view>
						</view>
						<view class="labelBox">
							<view class="supportReturn" v-if="!isNomalVirtual==3 && methodItem==0">支持七天无理由退货</view>
							<view class="selfSupport" v-if="orderInfo.goodsInfo.owner_id==1">自营</view>
							<!-- <view class="retreat" v-if="orderInfo.goods.return_any_time==1">
								<u-icon name="checkmark-circle" color="#40A9FF" size="26"></u-icon>
								随时退
							</view>
							<view class="retreat" v-if="orderInfo.goods.return_overdue==1">
								<u-icon name="checkmark-circle" color="#40A9FF" size="26"></u-icon>
								过期退
							</view> -->
						</view>
						<view class="goodsPrice">
							<view class="goodsPriceFl"><text>￥</text>{{orderInfo.checkedShop.price}}</view>
							<text>x {{orderInfo.num}}</text>
						</view>
					</view>
				</view>
				<view class="detailedItem">
					数量 
					<view class="goodsPriceFr">
						<u-number-box v-model="orderInfo.num" @change="valChange" bg-color="#fff" :min="1" input-width="72"></u-number-box>
					</view>
				</view>
				<view class="detailedItem">配送方式 <text class="fr">{{methodItem==1?(isNomalVirtual==2?'到店消费':'门店自提'):'线上发货'}}</text></view>
			</view>
			<!-- 其他的明细 -->
			<view class="otherDetailed mb16" v-if="orderInfo.checkedShop">
				
				<view class="detailedItem">
					订单金额 <text class="fr">￥{{parseFloat(orderInfo.num*orderInfo.checkedShop.price).toFixed(2)}}</text>
				</view>
				
				<view class="detailedItem" v-if="methodItem==0">
					运费 
					<text class="fr">￥{{parseFloat(orderInfo.goodsInfo.postage_price).toFixed(2)}}</text>
				</view>
				
				<!-- <view class="detailedItem">优惠券 {{couponList.use_yes.length}}
					<view v-if="couponList.use_yes.length==0" @tap="openCouponPop" class="grey">
						无可用
						<u-icon name="arrow-right" color="#999999" size="20"></u-icon>
					</view>
					<view v-else @tap="openCouponPop" class="orange">
						未选优惠券
						<u-icon name="arrow-right" color="#999999" size="20"></u-icon>
					</view>
				</view> -->
				<!-- <view class="detailedItem">金币抵扣
					<view class="fr">
						<u-switch v-model="scoreDeduct" active-color="#FF5238" @change="scoreDeductGo" size="38"></u-switch>
					</view>
					<view class="fr" v-if="useScore==1">
						<view class="deductCont">可抵扣
							<text>{{scoreDeductVal}}</text>元
						</view>
					</view>
				</view>
				<view class="detailedItem">高粱穗抵扣
					<view class="fr">
						<u-switch v-model="coinDeduct" active-color="#FF5238" @change="coinDeductGo" size="38"></u-switch>
					</view>
					<view class="fr" v-if="useCoin==1">
						<view class="deductCont">可抵扣
							<text>{{coinDeductVal}}</text>元
						</view>
					</view>
				</view> -->
				
			</view>
			
			<view class="total">
				<view style="font-size: 28rpx;">合计：<text style="color:#FF5238;">￥</text><text class="paymoney">{{payAmount}}</text></view>
				<view class="pay" @tap="pay">微信支付</view>
			</view>
			
			<image @click="cardStrGo" class="liquorCardStrategy mb16" v-if="methodItem==1 && isNomalVirtual==3" src="https://lovebirdopen.com/static/img/cBj/liquorCardStrategy1.png"></image>
			
			<!-- 支付时间提示 -->
			<view class="payTimeTipsBox" v-if="payTimeTips">
				<view class="payTimeTips">
					<view class="tips">请在30分钟内完成支付，我们将第一时间为您发货</view>
					<view class="close" @tap="closePayTimeTipsBox"><u-icon name="close" color="#7B5D34" size="22"></u-icon></view>
				</view>
			</view>
			
			<!-- 详情立即抢购 -->
			<view class="handleBox" :style="{paddingBottom:isIphoneX?'76rpx':''}" v-if="orderInfo.goods">
				<view class="handleFl">合计:<text class="unit">￥</text>
					<text class="total">{{parseFloat(payAmount).toFixed(2)}}</text>
				</view>
				<view class="payBtn" v-if="is_bind==0">
					<author-phone @isBindChange="isBindChange" height="84rpx" bgColor="linear-gradient(97deg, #42E29F 11.54%, #21C531 91.53%), #1AAD19;" fontColor="#fff" title="微信支付" borderRadius="66rpx"></author-phone>
				</view>
				<view class="payBtn" @tap="paySuccess" v-if="is_bind==1">微信支付</view>
			</view>
			
			<!-- 优惠券选择 -->
			<u-popup v-model="couponShow" mode="bottom" border-radius="8">
				<view class="popTitle">
					<view class="nav" :class="{navEd:couponType==1}" @tap="couponSwitch(1)">可用优惠券</view>
					<view class="nav" :class="{navEd:couponType==2}" @tap="couponSwitch(2)">不可用优惠券</view>
				</view>
				<!-- 可用优惠券 -->
				<view class="couponBox" v-if="couponType==1 && couponList">
					<u-empty text="无可用优惠券" mode="coupon" v-if="couponList.use_yes.length==0"></u-empty>
					<scroll-view class="boxScroll" scroll-y="true">
						<view class="couponEach" v-for="(item,index) of couponList.use_yes" :key="item.id">
							<view class="couponEachCont" :class="{boxShadow:cIndex == index && ruleShow}">
								<view class="couponEachSide">
									<view class="sideLeft">
										<view class="circle1"></view>
										<view class="circle2"></view>
										<view class="sideLeftCont">
											<view class="amount">
												<text v-if="item.type=='1' || item.type=='3' || item.type=='4' || item.type=='6'">¥</text>
												{{item.promotion_condition[0].content}}
												<text v-if="item.type=='2' || item.type=='5'">折</text>
											</view>
											<view class="tips">{{item.conditions.condition_type_name}}</view>
										</view>
									</view>
									<view class="sideRight">
										<view class="circle1"></view>
										<view class="circle2"></view>
										<view class="sideRightCont">
											<view class="sideRightContLeft">
												<view class="title ellipsis"><text>{{item.promotion[0].name}}</text></view>
												<view class="use">{{getdate(item.end_at,1)}}前使用</view>
												<view class="useRule" @tap="seeRule(index)">使用规则<u-icon name="arrow-down" color="#999999" size="12"></u-icon></view>
											</view>
											<view class="checkBox checkBoxEd" @tap="couponCheck(index,item.checkS)">
												<label class="radio">
													<radio color="#FF5238" :value="item.id" :checked="item.checkS" />
												</label>
											</view>
										</view>
									</view>
								</view>
							</view>
							<view class="ruleContent" v-if="ruleShow && cIndex == index" :data-index="index">
								<view class="ruleInfo">{{item.promotion[0].instruction}}</view>
							</view>
						</view>
					</scroll-view>
				</view>
				<!-- 不可用优惠券 -->	
				<view class="couponBox" v-if="couponType==2 && couponList">
					<u-empty text="无不可用优惠券" mode="coupon" v-if="couponList.use_no.length==0"></u-empty>
					<scroll-view class="boxScroll" scroll-y="true">
						<view class="couponEach" v-for="(item,index) of couponList.use_no" :key="item.id">
							<view class="couponEachCont" :class="{boxShadow:cIndex == index && ruleShow}">
								<view class="couponEachSide">
									<view class="sideLeft">
										<view class="circle1"></view>
										<view class="circle2"></view>
										<view class="sideLeftCont sideLeftCont1">
											<view class="amount">
												<text v-if="item.type=='1' || item.type=='3' || item.type=='4' || item.type=='6'">¥</text>
												{{item.content}}
												<text v-if="item.type=='2' || item.type=='5'">折</text>
											</view>
											<view class="tips">{{item.conditions.condition_type_name}}</view>
										</view>
									</view>
									<view class="sideRight">
										<view class="circle1"></view>
										<view class="circle2"></view>
										<view class="sideRightCont">
											<view class="sideRightContLeft">
												<view class="title ellipsis"><text>{{item.promotion.name}}</text></view>
												<view class="use">{{getdate(item.end_at,1)}}前使用</view>
												<view class="useRule" @tap="seeRule(index)">使用规则<u-icon name="arrow-down" color="#999999" size="12"></u-icon></view>
											</view>
										</view>
									</view>
								</view>
							</view>
							<view class="ruleContent" v-if="ruleShow && cIndex == index" :data-index="index">
								<view class="ruleInfo">{{item.conditions.result_type_name}}</view>
							</view>
						</view>
					</scroll-view>
				</view>
			</u-popup>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url:'/api/user/moreTableList', //接口地址
				// 商品类型  is_nomal_virtual   1实体商品 2虚拟商品 3酒卡商品
				isNomalVirtual:null,
				// 是否支持线下  is_online 是否支持线上发货 1支持 2不支持
				isOnline:null,
				// 运费类型 shipping_type  1、固定运费  2、运费模板  3、包邮
				shippingType:null,
				// 邮费
				postage:0,
				// 订单金额
				orderAmount:0,
				
				// 优惠金额
				couponPmt:0,
				// 是否选了优惠券
				isCoupon:true,
				// 手机机型
				modelmes:null,
				//用户资产
				userFund:null,
				// 详情参数（收货地址--可用优惠券）
				detailParams:{
					address:null,//收货地址
					coupon:null,//优惠券
				},
				isIphoneX:false,
				couGoodsId:null,
				goodsId:null,
				ownerId:null,
				//订单
				orderSub:{
					product:{
						id:'',
						num:1
					},
					ship_id:'',//收货地址id
					store_id:'',//自提门店id
					coupon:''
				},
				// 订单提示
				orderTipsCont:[
					'选择线上发货，将为您进行线上物流发货，这需要获取您的收货地址。',
					'选择自助取货，可在“我的-我的酒卡”里查看，您可凭借酒卡随时到门店进行提酒。',
					'选择线上发货，将为您进行线上物流发货，这需要获取您的收货地址。',
					'选择自助取货，可在“我的-我的订单”里查看，您可随时到门店进行提酒。'
				],
				//发货方式
				methodItem:1,
				orderInfo:null,
				//优惠券,
				couponShow:false,
				couponType:1,
				ruleShow:false,
				cIndex:'',
				// 过滤后的优惠券
				couponList:{
					use_yes:[],
					use_no:[],
				},
				// 优惠券缓存区
				couponCache:null,
				// 金币抵扣与否
				scoreDeduct:true,
				useScore:1,
				// 高粱穗抵扣与否
				coinDeduct:true,
				useCoin:1,
				//提货方式和数量进行本地储存以便确认订单使用
				orderRecord:{
					methodItem:1,//提货方式
					num:1//商品数量
				},
				// 是否绑定手机号
				is_bind:null,
				// 支付提示
				payTimeTips:true,
				orderNumber:null,
			}
		},
		onShow(){
			// 生成订单编号
			let outTradeNo = ""; //订单号
			for (let i = 0; i < 4; i++) //4位随机数，用以加在时间戳后面。
			{
				outTradeNo += Math.floor(Math.random() * 10);
			}
			// uni.setStorageSync('addOrdernum', this.GetDateNow() + outTradeNo); //时间戳，用来生成订单号。
			this.orderNumber= this.GetDateNow() + outTradeNo
			
			let orderinfo=uni.getStorageSync('checkedShop')
			this.orderInfo=orderinfo
			this.isNomalVirtual=orderinfo.goodsInfo.type
			// this.confirmOrder(this.goodsId)
		},
		onLoad: function (option) { //option为object类型，会序列化上个页面传递的参数
			var _this = this;
			// 判断机型iPhone X的
			this.modelmes = uni.getStorageSync('modelmes');
			if (this.modelmes.search('iPhone X') != -1) {
			   this.isIphoneX = true;
			}
			uni.getStorage({
				key: 'orderRecord',
				success: function (res) {
					_this.orderSub.product.num = res.data.num;
					_this.methodItem = res.data.methodItem;
				}
			});
			this.goodsId = option.id
			// this.isBind()
			if (!uni.getStorageSync('userInfo')) {
				//用户登录
				this.login();
			} else {
				//调用默认启动方法
				this.loadData();
			}
		},
		computed:{
			// 支付金额
			payAmount(){
				return parseFloat(this.orderInfo.num*this.orderInfo.checkedShop.price).toFixed(2)
				
			},
			
			// 金币抵扣
			scoreDeductVal(){
				return (this.useScore==1&&this.orderInfo)?parseFloat((this.orderSub.product.num*this.orderInfo.score)>this.orderInfo.score_all?this.orderInfo.score_all:(this.orderSub.product.num*this.orderInfo.score)).toFixed(2):0;
			},
			// 高粱穗抵扣
			coinDeductVal(){
				return (this.useCoin==1&&this.orderInfo)?parseFloat((this.orderSub.product.num*this.orderInfo.coin)>this.orderInfo.coin_all?this.orderInfo.coin_all:(this.orderSub.product.num*this.orderInfo.coin)).toFixed(2):0;
			}
		},
		methods: {
			loadData() {
				this.get_addressData();//收货地址查询
				this.get_couponData();//优惠券查询
				this.get_userFundData();//用户资产查询
			},
			
			// 用户资产
			async get_userFundData(){
				//-------主表查询参数(地址查询)
				let url = '/api/user/listData'; //接口地址
				let param = {};
				param.table = 'user_fund';//表名称
				param.listType = 1; //分页获取商品数据 1单条  2全部  3分页
				param.db = 1; //0获取缓存数据  1 获取非缓存数据  默认0
				param.dbNum = ''; //缓存编号   API默认以MD5(param)为编号
				param.where = {'user_id':uni.getStorageSync('userInfo').user_id}; //主表查询条件 无需给个字符空值
				
				const res = await this.$fly.post(url, {
					msg: JSON.stringify(param)
				});
				if (res.code == 200) {
					this.userFund=res.data
					console.log(res.data)
				} else {
					console.log(res);
				}
			},
			
			// 收货地址
			async get_addressData() {
				//-------主表查询参数(地址查询)
				let param = {};
				param.db = 1; //0获取缓存数据  1 获取非缓存数据  默认0
				param.dbNum = ''; //缓存编号   API默认以MD5(param)为编号
				param.table = 'ship_address';//主表名称
				param.listType = 2; //2查询全部  3分页查询
				param.order = ''; //表无自增ID时追加为默认排序 无需给个字符空值
				param.linkfield = ''; //主表关联字段名称（为空则非关联多表查询）
				param.where = {'is_default':1}; //主表查询条件 无需给个字符空值
				param.table_list =[];//多表参数数组名称 无需给个字符空或空数组
				
				const res = await this.$fly.post(this.url, {
					msg: JSON.stringify(param)
				});
				
				if (res.code == 200) {
					this.detailParams.address=res.data[0]
					console.log(res.data)
				} else {
					console.log(res);
				}
			},
			
			// 优惠券
			async get_couponData() {
				//-------主表查询参数(优惠券查询)		
				let param = {};
				param.db = 1; //0获取缓存数据  1 获取非缓存数据  默认0
				param.dbNum = ''; //缓存编号   API默认以MD5(param)为编号
				param.table = 'promotion_coupon';//主表名称
				param.listType = 2; //2查询全部  3分页查询
				param.order = ''; //表无自增ID时追加为默认排序 无需给个字符空值
				param.linkfield = 'promotion_id'; //主表关联字段名称（为空则非关联多表查询）
				param.where = {
					'owner_id':uni.getStorageSync('shop_id'),
					'status':0,
					'start_at':['<',uni.getStorageSync('userInfo').time],
					'end_at':['>',uni.getStorageSync('userInfo').time],
					}; //主表查询条件 无需给个字符空值
				param.table_list=[];//多表参数数组名称 无需给个字符空或空数组
				
				let param2 = {};
				param2.db = 1; //0获取缓存数据  1 获取非缓存数据  默认0
				param2.dbNum = ''; //缓存编号   API默认以MD5(param2)为编号
				param2.table = 'promotion';//主表名称
				param2.listType = 2; //2查询全部  3分页查询
				param2.order = ''; //表无自增ID时追加为默认排序 无需给个字符空值
				param2.linkfield = 'id'; //主表关联字段名称（为空则非关联多表查询）
				param2.where = {}; //主表查询条件 无需给个字符空值
				param.table_list.push(param2) //多表参数数组名称 无需给个字符空或空数组
				
				let param3 = {};
				param3.db = 1; //0获取缓存数据  1 获取非缓存数据  默认0
				param3.dbNum = ''; //缓存编号   API默认以MD5(param3)为编号
				param3.table = 'promotion_condition';//主表名称
				param3.listType = 2; //2查询全部  3分页查询
				param3.order = 'sort Asc'; //表无自增ID时追加为默认排序 无需给个字符空值
				param3.linkfield = 'promotion_id'; //主表关联字段名称（为空则非关联多表查询）
				param3.where = {}; //主表查询条件 无需给个字符空值
				param.table_list.push(param3) //多表参数数组名称 无需给个字符空或空数组
				
			
				const res = await this.$fly.post(this.url, {
					msg: JSON.stringify(param)
				});
				
				if (res.code == 200) {
					// this.couponList.use_yes=res.data[0]
					this.filterCoupon(res.data)
					this.couponCache=res.data//优惠券缓存区
					console.log(res.data)
				} else {
					console.log(res);
				}
			},
			
			//过滤优惠券
			filterCoupon(data){
				let orderInfo=this.orderInfo
				this.couponList={
					use_yes:[],
					use_no:[]
				}
				// 优惠券筛选
				data.forEach(item=>{
					if(item.promotion_condition[0].condition_type==1){
						if(orderInfo.num*orderInfo.checkedShop.price>=item.promotion_condition[0].condition){
							this.couponList.use_yes.push(item)
							console.log(this.couponList.use_yes,'yes')
						}else{
							this.couponList.use_no.push(item)
							console.log(this.couponList.use_no,'no')
						}
					}
					else{
						if(orderInfo.num>=item.promotion_condition[0].condition){
							this.couponList.use_yes.push(item)
							
						}else{
							this.couponList.use_no.push(item)
						}
					}
				})
			},
		
			// 下单
			async pay(){
				if(!this.orderNumber){
					this.$refs.uToast.show({
						title: '订单丢失',
						type: 'error',
					})
					return 
				}
				if(!this.detailParams.address==null){
					this.$refs.uToast.show({
						title: '请填写您的收货地址信息',
						type: 'error',
					})
					return 
				}
				let params={}
				params.orderNumber=this.orderNumber;//订单编号
				params.shop_id=uni.getStorageSync('shop_id');//商户ID
				params.user_id=uni.getStorageSync('userInfo').user_id;//用户ID
				params.address=this.detailParams.address.address;//收货地址
				params.phone=this.detailParams.address.phone;//收货联系电话
				params.name=this.detailParams.address.name;//收货人
				params.ps_type=this.methodItem;//配送方式
				params.paycount=this.payAmount;//商品合计(实付金额)
				params.shop_paycount=this.orderInfo.num*this.orderInfo.checkedShop.price//商品总价(应付金额)
				params.goods=[
					{
						goods_id:this.orderInfo.checkedShop.id,//商品ID
						goods_num:this.orderInfo.num,//商品数量
						goods_price:this.orderInfo.checkedShop.price,//商品价格
						goods_name:this.orderInfo.checkedShop.name,//商品名字
						goods_pic:this.orderInfo.image//商品图片
					}
				]
				const res = await this.$fly.post('/api/pay/addOrder', {
					msg: JSON.stringify(params)
				});
				
				if (res.code == 200) {
					this.$refs.uToast.show({
						title: '下单成功',
						type: 'success',
					})
					console.log(res.data)
					// 清空缓存
					
					
				} else {
					this.$refs.uToast.show({
						title: res.msg,
						type: 'error',
					})
					console.log(res);
				}
				
			},
		
		
		
		
		
		
		
			
			confirmOrder(id){
				this.apiget('/fun/order/confirm',{id:id}).then(res =>{
					if(res.data.status == 200 ) {
						var resData = res.data.data;
						this.isNomalVirtual = resData.goods.is_nomal_virtual;
						this.isOnline = resData.goods.is_online;
						this.ownerId = resData.goods.owner_id;
						this.orderInfo = resData;
						this.orderInfo.orderSub = this.orderSub;
						this.orderSub.ship_id = resData.address==null?'':resData.address.id;
						this.orderInfo.pricePay = parseFloat(this.orderInfo.goods.productItems.price);
						this.orderSub.product.id = resData.goods.productItems.id;
						this.shippingType = this.orderInfo.goods.shipping_type;
						// 优惠券确认
						this.couGoodsId = resData.goods.id;
						this.confirmCoupon();
					}
				})
			},
			addAddress(){
				this.orderRecord.methodItem = this.methodItem;
				this.orderRecord.num = this.orderSub.product.num;
				uni.setStorage({
				    key: 'orderRecord',
				    data: this.orderRecord
				});
				uni.navigateTo({
					url: '../address/address?id='+this.goodsId
				});
			},
			// 确认优惠券
			// confirmCoupon(){
			// 	this.apiget('/fun/order/confirm-coupon',{id:this.orderSub.product.id,num:this.orderSub.product.num,goods_id:this.couGoodsId}).then(res =>{
			// 		if(res.data.status == 200 ) {
			// 			this.couponList = res.data.data.promotion;
			// 			if(res.data.data.promotion != null){
			// 				if(res.data.data.promotion.use_yes.length>0){
			// 					this.couponList.use_yes.forEach((v,i)=>{
			// 						if(this.orderSub.coupon==v.id){
			// 							v.checkS = true;
			// 						}else{
			// 							v.checkS = false;
			// 						}
			// 					})
			// 					if(this.orderSub.coupon=='' && this.isCoupon==true){
			// 						this.couponList.use_yes[0].checkS = true;
			// 						this.orderSub.coupon = this.couponList.use_yes[0].id;
			// 					}
			// 				}
			// 			}
			// 			this.reckon();
			// 		}
			// 	})
			// },
			// 酒卡攻略
			cardStrGo(){
				uni.navigateTo({
					url: '../scanCode/cardStrategy'
				});
			},
			// 弹出优惠券选择
			openCouponPop(){
				this.couponShow = true;
			},
			couponSwitch(t){
				this.couponType = t;
			},
			// 优惠券弹切换
			couponCheck(index,sta){
				// type  结果类型 1:商品减固金额2:商品折扣
				// 3:商品一口价4:订单减固定金额5:订单折扣
				// 6:订单一口价
				this.couponList.use_yes.forEach((v,i)=>{
					v.checkS = false;
				})
				this.couponList.use_yes[index].checkS = !sta;
				this.couponShow = false;
				if(sta){
					this.orderSub.coupon = '';
					this.isCoupon = false;
				}else{
					this.orderSub.coupon = this.couponList.use_yes[index].id;
					this.isCoupon = true;
				}
				this.reckon();
			},
			// 更多规则
			seeRule(index){
				this.ruleShow = !this.ruleShow;
				this.cIndex = index;
			},
			valChange(e){
				// this.orderSub.product.num = e.value;
				
				// 优惠券改变
				// this.confirmCoupon();
				this.filterCoupon(this.couponCache)
			},
			// 金币抵扣与否
			scoreDeductGo(val){
				this.useScore = val?1:null;
				this.reckon();
			},
			// 高粱穗抵扣与否
			coinDeductGo(val){
				this.useCoin = val?1:null;
				this.reckon();
			},
			deliveryMethod(e){
				this.methodItem = e;
				this.reckon();
			},
			isBind(){
				this.testToken('/fun/member/is-bind-phone',{}).then(res => {
					if(res.data.status==200){//是否绑定手机
						this.is_bind = res.data.data.is_bind;
					}
				})
			},
			isBindChange(e){
				this.is_bind = e;
			},
			closePayTimeTipsBox(){
				this.payTimeTips = false;
			},
			// 计算各种金额的
			reckon(){
				var _this = this;
				this.apipost('/fun/order/create',{product:JSON.stringify(_this.orderSub.product),ship_id:_this.orderSub.ship_id,coupon:_this.orderSub.coupon,is_offline:this.methodItem,use_score:this.useScore,use_coin:this.useCoin,confirm:1}).then(res =>{
					if(res.data.status == 200 ) {
						var resData = res.data.data;
						this.postage = resData.cost_freight;
						this.orderAmount = resData.order_amount;
						this.payAmount = resData.pay_amount;
						this.couponPmt = resData.coupon_pmt;
					}
				})
			},
			
			
			
			paySuccess(){
				var _this = this;
				var jsonData = JSON.stringify(this.orderSub);
				if(this.methodItem==0 && this.orderSub.ship_id==''){
					uni.showToast({
						icon: 'none',
						duration:1000,
						title: '请填写您的收货地址信息'
					});
					return false;
				}
				
				// product:_this.orderSub.product,ship_id:_this.orderSub.ship_id,coupon:_this.orderSub.coupon
				this.apipost('/fun/order/create',{product:JSON.stringify(_this.orderSub.product),ship_id:_this.orderSub.ship_id,coupon:_this.orderSub.coupon,is_offline:this.methodItem,use_score:this.useScore,use_coin:this.useCoin}).then(res =>{
					if(res.data.status == 200 ) {
						var order_id = res.data.data.order_id;
						if(_this.isNomalVirtual==3 && _this.methodItem==1){
							var card_id = res.data.data.liquor_card[0].id;
						}
						this.apiget('/fun/pay/pay-params',{order_id:order_id,payment_code :'wechatpay',payment_type :'lite'}).then(res =>{
							if(res.data.status == 200 ) {
								uni.removeStorage({//付款成功清除掉
								    key: 'orderRecord'
								});
								var payData = res.data.data;
								payData.provider='wxpay';
								payData.success=function (res) {
									console.log('success:' + JSON.stringify(res));
									if(_this.isNomalVirtual==3){//酒卡
										if(_this.methodItem==0){//线上发货
											uni.redirectTo({
												url: './paySuccess?id='+order_id
											});	
										}else{//生成酒卡
											uni.redirectTo({
												url: './cardPaySuccess?id='+card_id
											});
										}
									}else if(_this.isNomalVirtual==1){//实物商品
										uni.redirectTo({
											url: './paySuccess?id='+order_id
										});
									}else{//虚拟商品
										uni.redirectTo({
											url: './paySuccess?id='+order_id
										});
									}
								};
								payData.fail=function (err) {
									console.log('fail:' + JSON.stringify(err));
								};
								uni.requestPayment(payData);
							}
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.confirmOrder{
		min-height: 100%;
		padding: 36rpx 32rpx 200rpx;
		background: #F8F8FA;
	}
	.mb16{
		margin-bottom: 16rpx;
	}
	.tipsContBox{
		// min-height: 100rpx;
		padding: 24rpx 32rpx;
		display: flex;
		background-image: url('https://lovebirdopen.com/static/img/cBj/addressLine.svg');
		background-repeat: repeat-x;
		background-position: left bottom;
		background-size: auto 6rpx;
		background-color: #fff;
		box-shadow: 0px 4rpx 8rpx rgba(0, 0, 0, 0.02);
		border-radius: 16rpx;
		
		.tipsCont{
			flex: auto;
			
			.tipsContTit{
				font-size: 32rpx;
				line-height: 48rpx;
				color: #333;
				
				text{
					margin-right: 20rpx;
				}
			}
			.tipsContInfo{
				font-size: 24rpx;
				line-height: 40rpx;
				color: #666;
			}
		}
	}
	
	.shoppingList{
		padding: 0 32rpx 16rpx;
		background-color: #fff;
		border-radius: 16rpx;
		
		.shopInfo{
			display: flex;
			padding: 34rpx 0 8rpx;
			font-size: 28rpx;
			line-height: 44rpx;
			
			.shopLogo{
				width: 40rpx;
				height: 40rpx;
				margin-right: 12rpx;
				border-radius: 50%;
				overflow: hidden;
			}
			.shopName{
				flex: 1;
				width: 1px;
			}
		}
		
		.goodsInfo{
			display: flex;
			padding: 24rpx 0;
			margin-bottom: 16rpx;
			
			image{
				width: 160rpx;
				height: 160rpx;
				border-radius: 8rpx;
				margin-right: 16rpx;
			}
			
			.niccImg{
				width: 160rpx;
				height: 160rpx;
				border-radius: 8rpx;
				margin-right: 16rpx;
			}
			
			.goodsInfoFr{
				flex: auto;
				width: 1px;
				font-size: 0;
				
				.goodsName{
					font-size: 28rpx;
					line-height: 44rpx;
					color: #333333;
				}
				
				.goodsLabel{
					display: inline-block;
					font-size: 22rpx;
					line-height: 32rpx;
					color: #999;
				}
				
				.labelBox{
					height: 34rpx;
					
					view{
						margin-right: 8rpx;
					}
					
					.supportReturn{
						display: inline-block;
						padding: 4rpx 8rpx;
						font-size: 20rpx;
						line-height: 20rpx;
						color: #FF5238;
						border: 1rpx solid #FF5238;
						border-radius: 4rpx;
					}
					
					.selfSupport{
						display: inline-block;
						padding: 4rpx 8rpx;
						font-size: 20rpx;
						line-height: 20rpx;
						color: #fff;
						background: linear-gradient(124.24deg, #FF5238 22.31%, #FF6838 70.25%);
						border-radius: 4rpx;
					}
					
					.retreat{
						display: inline-block;
						font-size: 22rpx;
						line-height: 34rpx;
						color: #40A9FF;
						
						.u-icon{
							margin-left: 4rpx;
						}
					}
				}
				
				.goodsPrice{
					display: flex;
					line-height: 48rpx;
					
					.goodsPriceFl{
						flex: auto;
						font-size: 32rpx;
						color: #FF5238;
						
						text{
							font-size: 24rpx;
						}
					}
					text{
						font-size: 28rpx;
						color: #999999;
					}
				}
			}
		}
		
		
		.detailedItem{
			padding: 18rpx 0;
			font-size: 26rpx;
			line-height: 44rpx;
			color: #333333;
			
			.goodsPriceFr{
				float: right;
			}
			
			.fr{
				float: right;
				padding-right: 24rpx;
			}
			
			.orange{
				float: right;
				padding-right: 0;
				color: #FF5238;
				
				.u-icon{
					margin-left: 4rpx;
				}
			}			
			.grey{
				float: right;
				padding-right: 0;
				color: #999;
				
				.u-icon{
					margin-left: 4rpx;
				}
			}
		}
		
		.deliveryMethod{
			display: flex;
			align-items: center;
			padding: 10rpx 0;
			
			.explain{
				flex: auto;
				font-size: 24rpx;
				line-height: 36rpx;
				
				.u-icon{
					margin-left: 14rpx;
				}
			}
			
			.methodItem{
				display: inline-block;
				padding: 10rpx 40rpx;
				margin-left: 16rpx;
				font-size: 24rpx;
				line-height: 40rpx;
				color: #666;
				border: 2rpx solid #999999;
				box-sizing: border-box;
				border-radius: 36rpx;
			}
			.methodItemEd{
				color: #FF5238;
				border: 2rpx solid #FF5238;
			}
		}
	}
	
	.otherDetailed{
		padding: 16rpx 32rpx;
		background-color: #fff;
		border-radius: 16rpx;
		box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.03);
		
		.detailedItem{
			padding: 18rpx 0;
			font-size: 28rpx;
			line-height: 44rpx;
			color: #333333;
			
			.fr{
				float: right;
				padding-right: 28rpx;
				
				.deductCont{
					color: #666;
					
					text{
						color: #FF5238;
					}
				}
			}
			
			.orange{
				float: right;
				padding-right: 28rpx;
				color: #FF5238;
				
				.u-icon{
					margin-left: 4rpx;
				}
			}			
			.grey{
				float: right;
				padding-right: 0;
				color: #999;
				
				.u-icon{
					margin-left: 4rpx;
				}
			}
		}
		
		
	}
	.total{
		position: fixed;
		bottom: 0;
		width: calc(100% - 64rpx);
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 26rpx 0;
		font-size: 28rpx;
		line-height: 44rpx;
		color: #333333;
		.pay{
			background: linear-gradient(97deg, #38DD7A 11.54%, #21C531 91.53%);
			border-radius: 66rpx;
			width: 208rpx;
			height: 84rpx;
			line-height: 84rpx;
			font-size: 32rpx;
			text-align: center;
			color: white;
		}
		.paymoney{
			color: #FF5238;
			font-size: 48rpx;
		}
	}
	.invoice{
		padding: 24rpx 32rpx 28rpx;
		background-color: #fff;
		font-size: 28rpx;
		line-height: 44rpx;
		
		text{
			float: right;
			color: #999999;
		}
	}
	
	
	.payTimeTipsBox{
		padding: 0 32rpx;
		position: fixed;
		bottom: 110rpx;
		left: 0;
		z-index: 11;
		width: 100%;
		
		.payTimeTips{
			display: flex;
			height: 80rpx;
			padding: 0 24rpx;
			line-height: 80rpx;
			font-size: 24rpx;
			color: #7B5D34;
			text-align: center;
			background: #FFF3DD;
			border-radius: 16rpx;
			
			.tips{
				flex: 1;
				width: 1px;
			}
			
			.close{
				width: 32rpx;
				text-align: right;
			}
		}
	}
	
	.handleBox{
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 2;
		width: 100%;
		display: flex;
		align-items: center;
		padding: 8rpx 32rpx;
		background-color: #fff;
		
		.handleFl{
			flex: auto;
			font-size: 28rpx;
			line-height: 44rpx;
			color: #333333;
			
			.unit{
				font-size: 24rpx;
				color: #FF5238;
				font-weight: 700;
			}
			.total{
				color: #FF5238;
				font-weight: 700;
			}
		}
		
		.payBtn{
			display: inline-block;
			height: 84rpx;
			padding: 0 40rpx;
			font-size: 32rpx;
			line-height: 84rpx;
			color: #fff;
			background: linear-gradient(97deg, #42E29F 11.54%, #21C531 91.53%);
			border-radius: 66rpx;
		}
	}
	
	// 弹窗里面内容样式
	.popTitle{
		display: flex;
		height: 100rpx;
		font-size: 32rpx;
		line-height: 100rpx;
		color: #333333;
		text-align: center;
		align-items: center;
		
		.nav{
			flex: 1;
		}
		
		.navEd{
			position: relative;
		}
		.navEd:after{
			position: absolute;
			content: '';
			bottom: 0;
			left: 50%;
			width: 48rpx;
			height: 8rpx;
			margin-left: -24rpx;
			background: #FF5238;
			border-radius: 12rpx;
		}
	}
	
	.specsBox{
		max-height: 660rpx;
		padding: 36rpx;
		background-color: #F8F8FA;
	}
	
	
	
	
	.couponBox{
		height: 660rpx;
		padding: 16rpx 36rpx;
		background-color: #F8F8FA;
		overflow-y: auto;
		.boxScroll{
			width: 100%;
			height: 100%;
		}
	}
	// 新优惠券
	.couponEach{
		position: relative;
		margin-bottom: 16rpx;
		min-height: 224rpx;
		padding-top: 196rpx;
		
		.couponEachCont{
			position: absolute;
			left: 0;
			top: 0;
			z-index: 2;
			height: 224rpx;
			width: 100%;
			// padding-right: 94rpx;
			box-sizing: border-box;
			
			.couponEachSide{
				display: flex;
				align-items: center;
				width: 100%;
				height: 100%;
				padding-right: 16rpx;
				background-color: #fff;
				border-radius: 16rpx;
				
				.sideLeftCont{
					text-align: center;
					height: 100%;
					padding: 18rpx;
					border-right: 2rpx dashed #ccc;
					color: #FF5238;
					
					.amount{
						font-size: 50rpx;
						line-height: 56rpx;
						
						text{
							font-size: 32rpx;
						}
					}
					
					.tips{
						font-size: 24rpx;
						line-height: 34rpx;
					}
				}
				.sideLeftCont1{
					color: #999999;
				}
				
				.sideLeft{
					position: relative;
					padding: 48rpx 0;
					width: 160rpx;
					height: 100%;
					
					.circle1{
						position: absolute;
						top: -14rpx;
						right: -14rpx;
						width: 28rpx;
						height: 28rpx;
						background-color: #F8F8FA;
						border-radius: 50%;
					}
					.circle2{
						position: absolute;
						bottom: -14rpx;
						right: -14rpx;
						width: 28rpx;
						height: 28rpx;
						background-color: #F8F8FA;
						border-radius: 50%;
					}
				}
				
				.sideRight{
					flex: 1;
					width: 1px;
					position: relative;
					padding: 48rpx 0 48rpx 32rpx;
					height: 100%;
					
					.sideRightCont{
						display: flex;
						align-items: center;
						
						.sideRightContLeft{
							flex: 1;
							width: 1px;
							
							.title{
								font-size: 28rpx;
								line-height: 40rpx;
								color: #666666;
								
								text{
									color: #333333;
									font-weight: 700;
									margin-right: 16rpx;
								}
							}
							
							.use{
								margin-top: 8rpx;
								font-size: 24rpx;
								line-height: 34rpx;
								color: #666666;
							}
							
							.useRule{
								margin-top: 20rpx;
								font-size: 24rpx;
								line-height: 34rpx;
								color: #999999;
								
								.u-icon{
									margin-left: 10rpx;
								}
							}
						}
						
						.checkBox{
							padding: 0 32rpx;
						}
						.checkBoxEd{
							.u-icon{
								color: #FF5238;
							}
						}
					}
					
					.circle1{
						position: absolute;
						top: -14rpx;
						left: -14rpx;
						width: 28rpx;
						height: 28rpx;
						background-color: #F8F8FA;
						border-radius: 50%;
					}
					.circle2{
						position: absolute;
						bottom: -14rpx;
						left: -14rpx;
						width: 28rpx;
						height: 28rpx;
						background-color: #F8F8FA;
						border-radius: 50%;
					}
				}
			}
		}
		
		.boxShadow{
			box-shadow: 0px 4rpx 60rpx -2rpx rgba(0, 0, 0, 0.05);
		}
		
		.ruleContent{
			padding: 50rpx 48rpx 22rpx;
			background: #FFFFFF;
			border-radius: 0px 0px 16rpx 16rpx;
			
			.ruleInfo{
				position: relative;
				padding-left: 15px;
				font-size: 12px;
				line-height: 24px;
				color: #333;
			}
			.ruleInfo:after{
				position: absolute;
				content: '';
				top: 50%;
				left: 14rpx;
				width: 4rpx;
				height: 4rpx;
				margin-top: -2rpx;
				background-color: #333;
			}
		}
	}
	.labelItem{
		display: inline-block;
		padding: 6rpx 40rpx;
		margin: 8rpx;
		font-size: 24rpx;
		line-height: 36rpx;
		color: #666666;
		border: 2rpx solid #999999;
		border-radius: 28rpx;
	}
	
	.labelItemEd{
		background: #FEF1EF;
		color: #EB4B34;
		border: 2rpx solid #EB4B34;
	}
	
	.deliveryMethod{
		background: #FFFFFF;
		border-radius: 16rpx;
		
		.navBox{
			display: flex;
			
			.nav{
				flex: 1;
				position: relative;
				width: 50%;
				height: 88rpx;
				line-height: 88rpx;
				font-size: 28rpx;
				color: #666666;
				text-align: center;
				box-sizing: border-box;
			}
			
			.navEd{
				border-bottom: 4rpx solid #FF5238;
				font-weight: 900;
				color: #333333;
			}
			
			.deMethodEd{
				position: absolute;
				left: 50%;
				bottom: 0;
				width: 342rpx;
				height: 24rpx;
				margin-left: -171rpx;
			}
		}
		
		.tips{
			padding: 16rpx 32rpx 24rpx;
			font-size: 24rpx;
			line-height: 40rpx;
			color: #666;
		}
	}
	
	.liquorCardStrategy{
		width: 100%;
		height: 240rpx;
	}
</style>
